import { createStore } from 'vuex'
import {ajax} from "@/api"

export default createStore({
  state: {
    userInfo:null,
    collapse:false,  // false 不收起  展开
    roleList:[],
    userList:[], // 用户列表 
  },
  mutations: {
    changeCollapse(state,payload){
      console.log(payload)
      state.collapse = payload ;
    },
    changeUserInfo(state,payload){
      console.log(payload)
      state.userInfo = payload; 
    },
    changeUser(state,payload){
      state.userInfo  = {...state.userInfo,...payload}
    },
    getRoleList(state,payload){
      console.log(payload)
      state.roleList = payload; 
    },
    getuserlist(state,payload){
      state.userList = payload; 
    }
  },
  actions: {
      async getRoleListAsync({commit}){
        let {result,code} = await ajax.getrolelist();
        if(code==200){
          commit('getRoleList',result)
        }
      },
      async getUserListAsync({commit},params){
        let {result,code} = await ajax.getuserlist(params);
        if(code==200){
          commit('getuserlist',result)
        }
      }
  },
  modules: {
  }
})
